package com.atguigu.gmall.cart.rpc;

import com.atguigu.gmall.cart.service.CartService;
import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.common.util.UserAuthToUtil;
import com.atguigu.gmall.model.cart.CartItem;
import com.atguigu.gmall.model.to.UserAuthTo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author A
 * @version 1.0
 * @description: TODO
 * @date 2024/10/5 2:35
 */
@RequestMapping("/rpc/inner/cart")
@RestController
public class CartRpcController {
    @Autowired
    CartService cartService;
    //addCart.html?skuId=42&skuNum=1
    //把商品添加进购物车
    @GetMapping("/addCart/{skuId}")
    public Result<CartItem> addSkuToCart(@PathVariable("skuId") Long skuId,
                                         @RequestParam Integer skuNum) {
        CartItem cartItem=cartService.addSkuToCart(skuId,skuNum);

        return Result.ok(cartItem);
    }
    @GetMapping("/deleteChecked")
    public Result deleteChecked(){
        cartService.deleteChecked();
        return Result.ok();
    }
    //返回勾选的cartItem
    @GetMapping("/getCartItemChecked")
    public Result<List<CartItem>> getCartItemForOrderVo(){
        List<CartItem> cartItemList =cartService.getCartItemForOrderVo();
        return Result.ok(cartItemList);
    }
}
